package com.chuck.blogpro.service.impl;

import com.chuck.blogpro.mapper.UserMapper;
import com.chuck.blogpro.pojo.User;
import com.chuck.blogpro.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service  // 将此对象交给 ioc 容器管理，生成 bean 对象, 具体在 impl 实现类中实现逻辑
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> getUsers() {
        return userMapper.getUsers();
    }

    @Override
    public User getUser(User user) {
        return userMapper.login(user.getUsername(), user.getPassword());
    }

    @Transactional(rollbackFor = Exception.class) // spring事务 管理
    @Override
    public void delete(Integer id) {

        userMapper.delete(id);
    }

    @Override
    public User getUserById(Integer id) {
        return userMapper.getUserById(id);
    }

    @Override
    public void update(User user) {
        userMapper.update(user);
    }

    @Override
    public void add(User user) {
        userMapper.add(user);
    }


}
